package com.shanling.shanlingcontroller.ui.fragment;

import android.os.Bundle;
import android.os.Parcelable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.shanling.shanlingcontroller.R;
import com.shanling.shanlingcontroller.base.BaseMVPFragment;
import com.shanling.shanlingcontroller.bean.Constants;
import com.shanling.shanlingcontroller.bean.EventCenter;
import com.shanling.shanlingcontroller.bean.Music;
import com.shanling.shanlingcontroller.persenter.SongsPresenter;
import com.shanling.shanlingcontroller.persenter.contract.SongFragmentContract;
import com.shanling.shanlingcontroller.ui.activity.MusicsOperatingActivity;
import com.shanling.shanlingcontroller.ui.activity.StyleDetailActivity;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

/**
 * Created by ch1 on 2019/11/22.
 */

public class StyleFragment extends BaseMVPFragment<SongFragmentContract.Presenter> implements SongFragmentContract.View {
    @BindView(R.id.tv_unkonw)
    TextView tvUnkonw;
    @BindView(R.id.tv_count)
    TextView tvCount;
    @BindView(R.id.rl_unkown)
    RelativeLayout rlUnkown;
    @BindView(R.id.bt_scan)
    Button btScan;
    @BindView(R.id.ll_nomusic)
    LinearLayout llNomusic;
    @BindView(R.id.pb)
    ProgressBar pb;
    private List<Music> musicList = new ArrayList<>();

    @Override
    protected void onLazyLoad() {


    }

    @Override
    protected int getContentViewLayoutID() {
        return R.layout.fragment_style;
    }

    @Override
    protected void initViewsAndEvents() {
        mPresenter.loadSongs(getActivity());

    }

    @Override
    protected boolean isBindEventBusHere() {
        return false;
    }

    @Override
    protected void onEventComing(EventCenter eventCenter) {

    }

    @OnClick(R.id.rl_unkown)
    public void onViewClicked() {
        Bundle bundle=new Bundle();
        bundle.putParcelableArrayList("musicList", (ArrayList<? extends Parcelable>) musicList);
        readyGo(StyleDetailActivity.class,bundle);
    }
    @Override
    public void showSongs(List<Music> songList) {
        llNomusic.setVisibility(View.INVISIBLE);
        pb.setVisibility(View.GONE);
        rlUnkown.setVisibility(View.VISIBLE);
        tvCount.setText(songList.size()+getString(R.string.songs));
        musicList.clear();
        musicList.addAll(songList);
    }

    @Override
    public void setEmptyView() {
        llNomusic.setVisibility(View.VISIBLE);
        pb.setVisibility(View.GONE);
        rlUnkown.setVisibility(View.GONE);
    }

    @Override
    public void showLoading() {
        pb.setVisibility(View.VISIBLE);
        llNomusic.setVisibility(View.INVISIBLE);
    }
    @Override
    public void hideLoading() {
        pb.setVisibility(View.GONE);
    }
    @Override
    protected SongFragmentContract.Presenter createPresenter() {
        return new SongsPresenter();
    }
}
